﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="DicasViagens.ItemPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DicasViagens"
    xmlns:data="using:DicasViagens.Data"
    xmlns:tiles="using:DicasViagens.VariableTemplate"      
    xmlns:common="using:DicasViagens.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
      
        <CollectionViewSource
            x:Name="ItemsViewSource"
            Source="{Binding Items}"
            IsSourceGrouped="False"
            d:Source="{Binding Items, Source={d:DesignInstance Type=data:HubPageDataSource, IsDesignTimeCreatable=True}}"/>

        <CollectionViewSource
            x:Name="subItemsViewSource"
            Source="{Binding SubItems}"
            IsSourceGrouped="False"
            d:Source="{Binding SubItems, Source={d:DesignInstance Type=data:HubPageDataSource, IsDesignTimeCreatable=True}}"/>

        <tiles:VariableTiles x:Key="MyTemplates"                             
                             SquareTemplate="{StaticResource SquareTemplate}"
                             NormalTemplate="{StaticResource NormalTemplate}"
                             VerticalTemplate="{StaticResource VerticalTemplate}"
                             DetailTemplate="{StaticResource DetailTemplate}"
                             SmallNormalTemplate="{StaticResource SmallNormalTemplate}"
                             SmallWideTemplate="{StaticResource SmallWideTemplate}"
                             SmallVerticalTemplate="{StaticResource SmallVerticalTemplate}">
        </tiles:VariableTiles>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">Leh- Ladakh</x:String>
    </Page.Resources>
    <common:LayoutAwarePage.TopAppBar>
        <AppBar Height="110" Background="#FF3238AA">
            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                <Button Content="Home" Height="92" Margin="5,0"  Style="{StaticResource AppBarHomeBtnStyle}" Width="92"/>
            </StackPanel>
        </AppBar>
    </common:LayoutAwarePage.TopAppBar>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ScrollViewer x:Name="scrollViewer" Grid.ColumnSpan="2" Grid.RowSpan="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="140"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Rectangle Fill="White" Grid.RowSpan="2" StrokeThickness="0" Visibility="Collapsed"/>

                <!-- Flipview para apresentar os itens -->
                <StackPanel Orientation="Vertical" Grid.Row="1" Width="637"  Margin="120,0,0,0">
                    <FlipView x:Name="flipItems" Width="637" VerticalAlignment="Top" Height="700" ItemsSource="{Binding Source={StaticResource ItemsViewSource}}" >
                        <FlipView.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="637" VerticalAlignment="Top"  >
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="430"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding ImageUrl}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Nome}" Width="626" Height="424" />
                                    <StackPanel Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Vertical" Margin="0,10,0,0"  Width="637">
                                        <TextBlock Text="{Binding Nome}" FontSize="24.66"/>
                                        <TextBlock Text="{Binding SubTitulo}" FontSize="20.66"/>
                                        <ScrollViewer Width="630" Height="200" Style="{StaticResource ScrollViewerStyle1}" VerticalScrollMode="Auto" >
                                            <TextBlock Text="{Binding Descricao}" FontSize="16.66" TextWrapping="Wrap" Height="Auto"/>
                                        </ScrollViewer> 
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </FlipView.ItemTemplate>
                    </FlipView>
                    
                </StackPanel>

                <StackPanel Grid.Column="1" Orientation="Horizontal" Grid.Row="1" Margin="0">

                    <!-- Dicas do item selecionado -->
                    <StackPanel Margin="100,0,0,0" Orientation="Vertical">


                        <TextBlock TextWrapping="Wrap" Text="SubItems" FontSize="29.333" FontFamily="Segoe UI" FontWeight="Light" HorizontalAlignment="Left" Margin="0"/>
                        <ScrollViewer Width="712"  Height="496" Style="{StaticResource ScrollViewerStyle1}">
                            <StackPanel Orientation="Vertical" Margin="10,5,0,0">
                                <GridView
        			            x:Name="dicasGridView"
        			            AutomationProperties.AutomationId="dicasGridView"
        			            AutomationProperties.Name="subItem Items"
        			            ItemsSource="{Binding Source={StaticResource subItemsViewSource}}"
                                ItemTemplate="{StaticResource SubItemTemplate}"
        			            SelectionMode="None"
        			            IsSwipeEnabled="false"
        			            IsItemClickEnabled="False"
        			            Margin="0">

                                    <GridView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <VirtualizingStackPanel Orientation="Vertical" Margin="0"/>
                                        </ItemsPanelTemplate>
                                    </GridView.ItemsPanel>
                                    

                                </GridView>

                                
                            </StackPanel>
                        </ScrollViewer>


                    </StackPanel>


                </StackPanel>



            </Grid>

        </ScrollViewer>


        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}" Margin="0,0,0,36" HorizontalAlignment="Center"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Nome}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" Grid.ColumnSpan="2" Margin="0,0,30,40" Grid.Column="1"/>
            <Rectangle x:Name="rectangle1" Fill="#FF1D1D1D" HorizontalAlignment="Right" Width="323" StrokeThickness="0" Grid.Column="1"/>
            <Image x:Name="image" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="1" Stretch="None" Source="Assets/AppLogo.png" Margin="0,0,48,0"/>
        </Grid>
        
        <TextBlock x:Name="textBlock" HorizontalAlignment="Center" TextWrapping="Wrap" Text="Está página é melhor visualizada em tele cheia!" VerticalAlignment="Center" Grid.Row="1" FontFamily="Segoe UI" FontSize="24" Visibility="Collapsed"/>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>-->

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,137,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="scrollViewer">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="image">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="pageTitle" d:IsOptimized="True" To="37.333"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="backButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <x:Double>NaN</x:Double>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="backButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <x:Double>NaN</x:Double>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="backButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>20,0,5,14</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>-50,0,10,50</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ColorAnimation Duration="0" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="pageTitle" d:IsOptimized="True" To="White"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="rectangle1">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="backButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <HorizontalAlignment>Left</HorizontalAlignment>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
